﻿using AutoMapper;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.Transplantation.Domain.Models;
using S.Transplantation.Infrastructure.InterFace;
using S.Transplantation.Read.Api.Application.Command;
using S.Transplantation.Read.Api.Dto;

namespace S.Transplantation.Read.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class TransplantationController : ControllerBase
    {
        private readonly IMapper mapper;
        private readonly IMediator mediator;
        private readonly IDescendantTransfertRepository DTRepository;

        public TransplantationController(IMediator mediator, IDescendantTransfertRepository DTRepository, IMapper mapper)
        {
            this.mapper = mapper;
            this.mediator = mediator;
            this.DTRepository = DTRepository;
        }
        /// <summary>
        /// 获取转种信息
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="beginTime"></param>
        /// <param name="endTime"></param>
        /// <param name="earTag"></param>
        /// <returns></returns>
        [HttpGet("GetTransplantationList")]
        public async Task<IActionResult> GetTransplantationList(int pageIndex, int pageSize, string? beginTime, string? endTime, string? earTag)
        {
            var result = await mediator.Send(new GetTransplantationListCommand() { BeginTime = beginTime, EndTime = endTime, PageIndex = pageIndex, PageSize = pageSize, EarTag = earTag });
            return Ok(result);
        }
        /// <summary>
        /// 反填转种信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// 
        [HttpGet("BackfillTransplantation")]
        public async Task<IActionResult> BackfillTransplantation(int id)
        {
            var requst = await mediator.Send(new BackfillTransplantationCommand() { Id = id });
            return Ok(requst);
        }
        
    }
}